/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */

/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
 
void preorder(struct TreeNode* root, int* res, int* resize){
    if(root == NULL) return ;
    res[(*resize)++] = root->val;
    preorder(root->left, res, resize);
    preorder(root->right, res, resize);
}

int* preorderTraversal(struct TreeNode* root, int* returnSize){
    int* res = (int*)malloc(sizeof(int)*200);
    if(res == NULL) assert(0);
    *returnSize  = 0;
    preorder(root, res, returnSize);
    return res;
}
